﻿using System;

namespace DynamicVm.Wpf
{
    class DelegateCommand<T> : DelegateCommandBase
    {
        public override bool CanExecute(object parameter)
        {
            return _canExecute == null || _canExecute((T) parameter);
        }

        public override void Execute(object parameter)
        {
            _execute((T) parameter);
        }

        public DelegateCommand(Action<T> execute, Func<T, bool> canExecute)
        {
            Contract.NotNull(execute, "execute");
            _execute = execute;
            _canExecute = canExecute;
        }

        private readonly Action<T> _execute;
        private readonly Func<T, bool> _canExecute;
    }
}
